<template>
  <div class="links">
    <div class="links_breadcrumb">
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item>当前位置</el-breadcrumb-item>
        <el-breadcrumb-item>首页</el-breadcrumb-item>
        <el-breadcrumb-item>{{ routerName }}</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="links_section">
      <div class="links_list">
        <div class="children_first">友情链接</div>
      </div>
      <div class="roter_view">
        <div class="course_news">
          <div class="course_news_title">
            <p style="margin-right: 20px">友情链接</p>
          </div>
          <div class="course_news_table">
            <el-table :data="linksList" style="width: 100%">
              <el-table-column fixed prop="label" label="名称">
              </el-table-column>
              <el-table-column fixed prop="content" label="描述">
              </el-table-column>
              <el-table-column fixed label="地址">
                <template slot-scope="scope">
                  <el-tooltip
                    class="item"
                    effect="dark"
                    :content="scope.row.url"
                    placement="bottom"
                  >
                    <p class="course_news_table_url">{{ scope.row.url }}</p>
                  </el-tooltip>
                </template>
              </el-table-column>
              <el-table-column prop="createdAt" label="创建时间" width="200">
              </el-table-column>
              <el-table-column prop="updatedAt" label="更新时间" width="200">
              </el-table-column>
            </el-table>
          </div>
          <div class="course_news_pagination">
            <el-pagination
              @current-change="handleCurrentChange"
              :current-page.sync="linksData.page"
              :page-size="linksData.size"
              layout="total, prev, pager, next"
              :total="total"
            >
            </el-pagination>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getLinksList } from "@/api/home";
export default {
  name: "index",
  data() {
    return {
      routerName: "",
      linksData: {
        page: 1,
        size: 10,
      },
      linksList: [],
      total: 0,
    };
  },
  created() {
    this.routerName = this.$route.query.routerName;
  },
  mounted() {
    this.getLinksList(this.linksData);
  },
  methods: {
    // 获取列表
    getLinksList(data) {
      getLinksList(data).then((response) => {
        if (response.data.code === 20000) {
          const { list, totalRecords } = response.data.results;
          this.total = totalRecords;
          this.linksList = list.map((item) => {
            return {
              id: item.id,
              label: item.title,
              content: item.content,
              url: item.url,
              createdAt: item.createdAt,
              updatedAt: item.updatedAt,
            };
          });
        }
      });
    },
    handleCurrentChange(val) {
      this.linksData.page = val;
      this.getLinksList(this.linksData);
    },
  },
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.el-tooltip__popper {
  max-width: 700px;
}
</style>

<style rel="stylesheet/scss" lang="scss" scoped>
.links {
  width: 1280px;
  margin: 0 auto;

  .links_breadcrumb {
    padding: 20px;
    padding-left: 0;
  }

  .links_section {
    display: flex;
    justify-content: space-between;

    .links_list {
      text-align: center;
      font-weight: bold;

      .children_first {
        width: 200px;
        height: 56px;
        line-height: 56px;
        border: 1px solid #f1f1f1;
        background: #f1f1f1;
        color: #0a7b19;
      }
    }
  }
  .course_news_pagination {
    width: 900px;
    margin: 0 auto;
    display: flex;
    justify-content: center;
    margin-bottom: 50px;
  }
  .roter_view {
    width: 1060px;
  }
  .course_news_title {
    height: 40px;
    background: #f1f1f1;
    text-align: right;
    line-height: 40px;
    font-weight: bold;
    font-size: 21px;
    color: #0a7b19;
  }
  .course_news_table {
    margin-top: 20px;
    margin-bottom: 50px;
    .el-button--text {
      color: #0a7b19;
    }
  }
  .course_news_pagination {
    width: 900px;
    margin: 0 auto;
    display: flex;
    justify-content: center;
    margin-bottom: 50px;
  }
  .course_news_table_url {
    overflow: hidden; //溢出隐藏
    white-space: nowrap; //禁止换行
    text-overflow: ellipsis;
  }
}
</style>
